package sudroid.android.graphics.gif;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import java.io.InputStream;
import sudroid.LogUtils;

public class GifView extends View
  implements Action
{
  private GifImageType animationType;
  private Bitmap currentImage = null;
  private DrawThread drawThread = null;
  private Decoder gifDecoder = null;
  private boolean isRun = 1;
  private boolean pause = 0;
  private Rect rect = null;
  private int showWidth = -1;

  public GifView(Context paramContext)
  {
    super(paramContext);
    GifImageType localGifImageType = GifImageType.SYNC_DECODER;
    this.animationType = localGifImageType;
  }

  public GifView(Context paramContext, AttributeSet paramAttributeSet)
  {
    this(paramContext, paramAttributeSet, 0);
  }

  public GifView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    GifImageType localGifImageType = GifImageType.SYNC_DECODER;
    this.animationType = localGifImageType;
  }

  private void setGifDecoderImage(InputStream paramInputStream)
  {
    if (this.gifDecoder != null)
    {
      this.gifDecoder.free();
      this.gifDecoder = null;
    }
    Decoder localDecoder = new Decoder(paramInputStream, this, 0);
    this.gifDecoder = localDecoder;
    this.gifDecoder.start();
  }

  private void setGifDecoderImage(byte[] paramArrayOfByte)
  {
    if (this.gifDecoder != null)
    {
      this.gifDecoder.free();
      this.gifDecoder = null;
    }
    Decoder localDecoder = new Decoder(paramArrayOfByte, this, 0);
    this.gifDecoder = localDecoder;
    this.gifDecoder.start();
  }

  protected void onDraw(Canvas paramCanvas)
  {
    super.onDraw(paramCanvas);
    if (this.gifDecoder == null);
    do
    {
      return;
      if (this.currentImage != null)
        continue;
      Bitmap localBitmap1 = this.gifDecoder.getImage();
      this.currentImage = localBitmap1;
    }
    while (this.currentImage == null);
    int i = paramCanvas.getSaveCount();
    int j = paramCanvas.save();
    float f1 = getPaddingLeft();
    float f2 = getPaddingTop();
    paramCanvas.translate(f1, f2);
    if (this.showWidth == -1)
    {
      Bitmap localBitmap2 = this.currentImage;
      paramCanvas.drawBitmap(localBitmap2, 0.0F, 0.0F, null);
    }
    while (true)
    {
      paramCanvas.restoreToCount(i);
      break;
      Bitmap localBitmap3 = this.currentImage;
      Rect localRect = this.rect;
      paramCanvas.drawBitmap(localBitmap3, null, localRect, null);
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    int i = getPaddingLeft();
    int j = getPaddingRight();
    int k = getPaddingTop();
    int m = getPaddingBottom();
    int n;
    if (this.gifDecoder == null)
      n = 1;
    for (int i1 = 1; ; i1 = this.gifDecoder.height)
    {
      int i2 = i + j;
      int i3 = n + i2;
      int i4 = k + m;
      int i5 = i1 + i4;
      int i6 = getSuggestedMinimumWidth();
      int i7 = Math.max(i3, i6);
      int i8 = getSuggestedMinimumHeight();
      int i9 = Math.max(i5, i8);
      int i10 = resolveSize(i7, paramInt1);
      int i11 = resolveSize(i9, paramInt2);
      setMeasuredDimension(i10, i11);
      return;
      n = this.gifDecoder.width;
    }
  }

  public void parseOk(boolean paramBoolean, int paramInt)
  {
    if (paramBoolean)
    {
      if (this.gifDecoder == null)
        break label255;
      int[] arrayOfInt = $SWITCH_TABLE$sudroid$android$graphics$gif$GifView$GifImageType();
      int i = this.animationType.ordinal();
      switch (arrayOfInt[i])
      {
      default:
      case 1:
      case 3:
      case 2:
      }
    }
    while (true)
    {
      return;
      if (paramInt != -1)
        continue;
      if (this.gifDecoder.getFrameCount() > 1)
      {
        new DrawThread(null).start();
        continue;
      }
      postInvalidate();
      continue;
      if (paramInt == 1)
      {
        Bitmap localBitmap1 = this.gifDecoder.getImage();
        this.currentImage = localBitmap1;
        postInvalidate();
        continue;
      }
      if (paramInt != -1)
        continue;
      if (this.gifDecoder.getFrameCount() > 1)
      {
        if (this.drawThread != null)
          continue;
        DrawThread localDrawThread1 = new DrawThread(null);
        this.drawThread = localDrawThread1;
        this.drawThread.start();
        continue;
      }
      postInvalidate();
      continue;
      if (paramInt == 1)
      {
        Bitmap localBitmap2 = this.gifDecoder.getImage();
        this.currentImage = localBitmap2;
        postInvalidate();
        continue;
      }
      if (paramInt == -1)
      {
        postInvalidate();
        continue;
      }
      if (this.drawThread != null)
        continue;
      DrawThread localDrawThread2 = new DrawThread(null);
      this.drawThread = localDrawThread2;
      this.drawThread.start();
      continue;
      label255: LogUtils.e("gif parse error");
    }
  }

  public void setGifImage(int paramInt)
  {
    InputStream localInputStream = getResources().openRawResource(paramInt);
    setGifDecoderImage(localInputStream);
  }

  public void setGifImage(InputStream paramInputStream)
  {
    setGifDecoderImage(paramInputStream);
  }

  public void setGifImage(byte[] paramArrayOfByte)
  {
    setGifDecoderImage(paramArrayOfByte);
  }

  public void setGifImageType(GifImageType paramGifImageType)
  {
    if (this.gifDecoder == null)
      this.animationType = paramGifImageType;
  }

  public void setShowDimension(int paramInt1, int paramInt2)
  {
    if ((paramInt1 > 0) && (paramInt2 > 0))
    {
      this.showWidth = paramInt1;
      Rect localRect = new Rect();
      this.rect = localRect;
      this.rect.left = 0;
      this.rect.top = 0;
      this.rect.right = paramInt1;
      this.rect.bottom = paramInt2;
    }
  }

  public void showAnimation()
  {
    if (this.pause)
      this.pause = 0;
  }

  public void showCover()
  {
    if (this.gifDecoder == null);
    while (true)
    {
      return;
      this.pause = 1;
      Bitmap localBitmap = this.gifDecoder.getImage();
      this.currentImage = localBitmap;
      invalidate();
    }
  }

  class DrawThread extends Thread
  {
    private DrawThread()
    {
    }

    public void run()
    {
      if (GifView.this.gifDecoder == null)
        return;
      label86: 
      while (true)
      {
        if (!GifView.this.pause)
        {
          Frame localFrame = GifView.this.gifDecoder.next();
          GifView localGifView = GifView.this;
          Bitmap localBitmap = localFrame.image;
          localGifView.currentImage = localBitmap;
          long l = localFrame.delay;
          GifView.this.postInvalidate();
          SystemClock.sleep(l);
        }
        while (true)
        {
          if (GifView.this.isRun)
            break label86;
          break;
          SystemClock.sleep(10L);
        }
      }
    }
  }

  public enum GifImageType
  {
    final int nativeInt;

    static
    {
      SYNC_DECODER = new GifImageType("SYNC_DECODER", 1, 1);
      COVER = new GifImageType("COVER", 2, 2);
      GifImageType[] arrayOfGifImageType = new GifImageType[3];
      GifImageType localGifImageType1 = WAIT_FINISH;
      arrayOfGifImageType[0] = localGifImageType1;
      GifImageType localGifImageType2 = SYNC_DECODER;
      arrayOfGifImageType[1] = localGifImageType2;
      GifImageType localGifImageType3 = COVER;
      arrayOfGifImageType[2] = localGifImageType3;
      ENUM$VALUES = arrayOfGifImageType;
    }

    private GifImageType(int arg3)
    {
      int j;
      this.nativeInt = j;
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.android.graphics.gif.GifView
 * JD-Core Version:    0.6.0
 */